import axios from 'axios';
import { LOGIN } from './actionTypes';

const changeLogin = () => {
    return {
        type: LOGIN,
        value: true,
    }
}

export const chageLogout = () => {
    return {
        type: LOGIN,
        value: false,
    }
}

export const login = (account, password) => {
    return (dispatch) => {
        axios.get(`https://www.fastmock.site/mock/eaa7a18e424aefd6b9ee29850969298e/api/login?account=${account}&password=${password}`).then(res => {
            const result = res.data.data;
            if (result) {
                const action = changeLogin();
                dispatch(action);
            } else {
                alert('登陆失败')
            }
        }).catch(()=>{
            console.log('error')
        })
    }
}